package com.web.web;


import com.web.entity.UserInfo;
import com.web.param.AdminLoginDto;
import com.web.param.InsertUserDto;
import com.web.param.UpdatePasswordDto;
import com.web.service.IUserInfoService;
import com.web.util.BaseController;
import com.web.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hgjxyz
 * @since 2020-11-18
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/web/userInfo")
public class UserInfoController extends BaseController {

    @Autowired private IUserInfoService userInfoService;

    @ApiOperation("添加用户")
    @PostMapping("add")
    public JsonResult<Void> addUser(@RequestBody InsertUserDto dto) {
        this.userInfoService.addUser(dto);
        return new JsonResult<>(null);
    }

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonResult<UserInfo> login(@RequestBody AdminLoginDto dto) {
        return new JsonResult<>(this.userInfoService.login(dto));
    }

    @ApiOperation("修改密码")
    @PostMapping("update/password")
    public JsonResult<Void> updatePwd(@RequestBody UpdatePasswordDto dto) {
        this.userInfoService.updatePassword(dto);
        return new JsonResult<>(null);
    }

}

